<!doctype html>
<html>
<head>
    <title>Trigger</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf8" />

    <link href='css/bootstrap.min.css' rel="stylesheet" />
    <link href="css/bootstrap-table.min.css" rel="stylesheet">
    <link href="css/bootstrapValidator.min.css" rel="stylesheet">
    <link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet">
    <link href='css/common.css' rel="stylesheet" />

    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/json2.min.js"></script>
    <script type="text/javascript" src="js/bootbox.min.js" charset="utf8"></script>
    <script type="text/javascript" src="js/doT.min.js" charset="utf8"></script>
    <script src="js/bootstrap-table.min.js"></script>
    <script src="js/bootstrap-table-zh-CN.min.js"></script>
    <script src="js/bootstrapValidator.min.js"></script>
    <script src="js/bootstrap-datetimepicker.min.js"></script>
    <script src="js/zh_CN.min.js"></script>
    <script type="text/javascript" src="js/common.js" charset="utf8"></script>
</head>
<body>
<div style="float:right;margin-right:20px;">
    <h6><a class="langSelector" langNow="0">English</a> | <a class="langSelector" langNow="1">中文</a></h6>
</div>
<!--在jquery中用ajax加载导航信息-->
<div class="container">
    <div id="banner">
        <h3>

        </h3>
    </div>
    <div class="page-header">
        <div class="row">
            <div class="col-lg-12">
                <div class="well">
                    <form class="form-horizontal" id="dataForm">
                        <div class="form-group">
                            <label for="schedulerName" class="col-lg-2 control-label">
                                SchedulerName<span style="color: red">*</span>
                            </label>
                            <div class="col-lg-9">
                                <input type="text" class="form-control" id="schedulerName" name="schedulerName" readonly="readonly">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="jobName" class="col-lg-2 control-label">
                                jobName<span style="color: red">*</span>
                            </label>
                            <div class="col-lg-9">
                                <input type="text" class="form-control" id="jobName" name="jobName" readonly="readonly">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="jobGroup" class="col-lg-2 control-label">
                                jobGroup<span style="color: red">*</span>
                            </label>
                            <div class="col-lg-9">
                                <input type="text" class="form-control" id="jobGroup" name="jobGroup" readonly="readonly">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="jobClass" class="col-lg-2 control-label">
                                jobClass<span style="color: red">*</span>
                            </label>
                            <div class="col-lg-9">
                                <input type="text" class="form-control" id="jobClass" name="jobClass" readonly="readonly">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div id="content">
    </div>
    <!-- 模板写到content外面防止被覆盖，正常情况覆盖没有问题，因为需要ajax重新加载所以在外面声明 -->
    <script id="triggerInfo-tmpl" type="text/x-dot-template">

        <div class="row">
            <div class="col-lg-12">
                <table id="dataTable" class="table table-striped table-bordered dataTable">
                    <thead>
                    <tr>
                        <th>triggerName</th>
                        <th>triggerGroup</th>
                        <th>cronExpression</th>
                        <th>triggerState</th>
                        <th>previousFireTime</th>
                        <th>nextFireTime</th>
                        <th>priority</th>
                        <th>startTime</th>
                        <th>endTime</th>
                        <th>misfireInstruction</th>
                        <th>finalFireTime</th>
                        <th>fireTimeAfter</th>
                        <th>calendarName</th>
                        <th>description</th>
                        <th>operation</th>
                    </tr>
                    </thead>
                    <tbody>
                    {{~ it.content :triggerInfo:i  }}
                    <tr>
                        <td>{{= triggerInfo.triggerName}}</td>
                        <td>{{= triggerInfo.triggerGroup}}</td>
                        <td>{{= triggerInfo.cronExpression}}</td>
                        <td>{{= triggerInfo.triggerState}}</td>
                        <td>{{= triggerInfo.previousFireTime}}</td>
                        <td>{{= triggerInfo.nextFireTime}}</td>
                        <td>{{= triggerInfo.priority}}</td>
                        <td>{{= triggerInfo.startTime}}</td>
                        <td>{{= triggerInfo.endTime}}</td>
                        <td>{{= triggerInfo.misfireInstruction}}</td>
                        <td>{{= triggerInfo.finalFireTime}}</td>
                        <td>{{= triggerInfo.fireTimeAfter}}</td>
                        <td>{{= triggerInfo.calendarName}}</td>
                        <td>{{= triggerInfo.description}}</td>
                        <td>
                            <a  href="triggerAdd.html?schedulerName={{= triggerInfo.schedulerName }}&jobName={{= triggerInfo.jobName }}&jobGroup={{= triggerInfo.jobGroup }}&triggerName={{= triggerInfo.triggerName }}&triggerGroup={{= triggerInfo.triggerGroup }}&type=modify">
                                modify|
                            </a>
                            <a  href="javascript:;"
                                onclick="javascript:quartzweb.trigger.ajaxRequestForTriggerRun('{{= triggerInfo.schedulerName }}','{{= triggerInfo.triggerName }}','{{= triggerInfo.triggerGroup }}')">
                                run|
                            </a>
                            <a  href="javascript:;"
                                onclick="javascript:quartzweb.trigger.ajaxRequestForTriggerPause('{{= triggerInfo.schedulerName }}','{{= triggerInfo.triggerName }}','{{= triggerInfo.triggerGroup }}')">
                                pause|
                            </a>
                            <a  href="javascript:;"
                                onclick="javascript:quartzweb.trigger.ajaxRequestForTriggerResume('{{= triggerInfo.schedulerName }}','{{= triggerInfo.triggerName }}','{{= triggerInfo.triggerGroup }}')">
                                resume|
                            </a>
                            <a  href="javascript:;"
                                onclick="javascript:quartzweb.trigger.ajaxRequestForTriggerRemove('{{= triggerInfo.schedulerName }}','{{= triggerInfo.triggerName }}','{{= triggerInfo.triggerGroup }}')">
                                remove|
                            </a>
                        </td>
                    </tr>
                    {{~ }}
                    </tbody>
                </table>
            </div>
        </div>
    </script>
</div>

<!--脚部信息-->
<div id="footer"></div>

<script type="text/javascript">

    $.namespace("quartzweb.trigger");
    quartzweb.trigger = function () {
        return {
            init: function (index) {
                // 加载头部
                quartzweb.common.createHeaderHTML(index);
                // 加载尾部
                quartzweb.common.createFooterHTML();
                // 设置变量名称
                var schedulerName = quartzweb.common.getWindowhrefVar("schedulerName");
                $("#schedulerName").val(schedulerName);
                // 设置变量名称
                var jobName = quartzweb.common.getWindowhrefVar("jobName");
                $("#jobName").val(jobName);
                // 设置变量名称
                var jobGroup = quartzweb.common.getWindowhrefVar("jobGroup");
                $("#jobGroup").val(jobGroup);
                var jobClass = quartzweb.common.getWindowhrefVar("jobClass");
                $("#jobClass").val(jobClass);


                quartzweb.trigger.ajaxRequestForTriggerInfo(schedulerName,jobName,jobGroup);
            },
            ajaxRequestForTriggerInfo: function (schedulerName, jobName, jobGroup) {

                $.ajax({
                    type: 'POST',
                    url: "api/triggerInfo.json",
                    data:{
                        schedulerName:schedulerName,
                        jobName:jobName,
                        jobGroup:jobGroup
                    },
                    success: function (data) {
                        if (1 === data.resultCode) {

                            var tmpl = $('#triggerInfo-tmpl').html();
                            var doTtmpl = doT.template(tmpl);
                            var contentHtml = doTtmpl(data);
                            $("#content").html(contentHtml);
                            // 设置bootstrap table样式
                            $("#dataTable").bootstrapTable({
                                search: true,  //是否显示搜索框功能
                                pagination: true,  //是否分页
                                pageList:[10,25,50,100],
                                striped:true,//隔行变成色
                                showToggle: true,
                                showColumns: true

                            });
                            //6 - priority
                            $("#dataTable").bootstrapTable('hideColumn',6);
                            //7 - startTime
                            $("#dataTable").bootstrapTable('hideColumn',7);
                            //8 - endTime
                            $("#dataTable").bootstrapTable('hideColumn',8);
                            //9 - misfireInstruction
                            $("#dataTable").bootstrapTable('hideColumn',9);
                            // finalFireTime
                            $("#dataTable").bootstrapTable('hideColumn',10);
                            //fireTimeAfter
                            $("#dataTable").bootstrapTable('hideColumn',11);
                            //calendarName
                            $("#dataTable").bootstrapTable('hideColumn',12);
                            //description
                            //$("#dataTable").bootstrapTable('hideColumn',13);

                        } else {
                            alert("system is error : " + data.content);
                        }
                    },
                    dataType: "json"
                })
            },
            // 重启trigger
            ajaxRequestForTriggerResume:function (schedulerName,triggerName,triggerGroup) {
                bootbox.confirm({
                    title: '系统提示',
                    message: '确定要重启['+triggerName+':'+triggerGroup+']',
                    buttons: {
                        confirm: {
                            label: 'OK',
                            className: ''
                        },
                        cancel: {
                            label: 'Cancel',
                        }
                    },
                    callback: function (result) {
                        if(result===true){
                            $.ajax({
                                type: 'POST',
                                url: 'api/triggerResume.json',
                                dataType: "json",
                                data:{
                                    schedulerName:schedulerName,
                                    triggerName:triggerName,
                                    triggerGroup:triggerGroup
                                },
                                success: function(data) {
                                    if(1 === data.resultCode){
                                        alert("ok");
                                        var schedulerName = $("#schedulerName").val();
                                        var jobName = $("#jobName").val();
                                        var jobGroup = $("#jobGroup").val();
                                        quartzweb.trigger.ajaxRequestForTriggerInfo(schedulerName,jobName,jobGroup);
                                    } else {
                                        alert("system is error:" + data.content);
                                    }
                                }

                            });
                        }
                    }
                });
            },
            //暂停trigger
            ajaxRequestForTriggerPause:function (schedulerName,triggerName,triggerGroup) {
                bootbox.confirm({
                    title: '系统提示',
                    message: '确定要暂停['+triggerName+':'+triggerGroup+']',
                    buttons: {
                        confirm: {
                            label: 'OK',
                            className: ''
                        },
                        cancel: {
                            label: 'Cancel',
                        }
                    },
                    callback: function (result) {
                        if(result===true){
                            $.ajax({
                                type: 'POST',
                                url: 'api/triggerPause.json',
                                dataType: "json",
                                data:{
                                    schedulerName:schedulerName,
                                    triggerName:triggerName,
                                    triggerGroup:triggerGroup
                                },
                                success: function(data) {
                                    if(1 === data.resultCode){
                                        alert("ok");
                                        var schedulerName = $("#schedulerName").val();
                                        var jobName = $("#jobName").val();
                                        var jobGroup = $("#jobGroup").val();
                                        quartzweb.trigger.ajaxRequestForTriggerInfo(schedulerName,jobName,jobGroup);
                                    } else {
                                        alert("system is error:" + data.content);
                                    }
                                }

                            });
                        }
                    }
                });
            },
            ajaxRequestForTriggerRemove:function (schedulerName,triggerName,triggerGroup) {
                bootbox.confirm({
                    title: '系统提示',
                    message: '确定要移除['+triggerName+':'+triggerGroup+']',
                    buttons: {
                        confirm: {
                            label: 'OK',
                            className: ''
                        },
                        cancel: {
                            label: 'Cancel',
                        }
                    },
                    callback: function (result) {
                        if(result===true){
                            $.ajax({
                                type: 'POST',
                                url: 'api/triggerRemove.json',
                                dataType: "json",
                                data:{
                                    schedulerName:schedulerName,
                                    triggerName:triggerName,
                                    triggerGroup:triggerGroup
                                },
                                success: function(data) {
                                    if(1 === data.resultCode){
                                        alert("ok");
                                        var schedulerName = $("#schedulerName").val();
                                        var jobName = $("#jobName").val();
                                        var jobGroup = $("#jobGroup").val();
                                        quartzweb.trigger.ajaxRequestForTriggerInfo(schedulerName,jobName,jobGroup);
                                    } else {
                                        alert("system is error:" + data.content);
                                    }
                                }

                            });
                        }
                    }
                });
            },
            // 执行一次
            ajaxRequestForTriggerRun:function (schedulerName,triggerName,triggerGroup) {
                bootbox.confirm({
                    title: '系统提示',
                    message: '确定要立即执行['+triggerName+':'+triggerGroup+']',
                    buttons: {
                        confirm: {
                            label: 'OK',
                            className: ''
                        },
                        cancel: {
                            label: 'Cancel',
                        }
                    },
                    callback: function (result) {
                        if(result===true){
                            $.ajax({
                                type: 'POST',
                                url: 'api/triggerRun.json',
                                dataType: "json",
                                data:{
                                    schedulerName:schedulerName,
                                    triggerName:triggerName,
                                    triggerGroup:triggerGroup
                                },
                                success: function(data) {
                                    if(1 === data.resultCode){
                                        alert("ok");
                                        var schedulerName = $("#schedulerName").val();
                                        var jobName = $("#jobName").val();
                                        var jobGroup = $("#jobGroup").val();
                                        quartzweb.trigger.ajaxRequestForTriggerInfo(schedulerName,jobName,jobGroup);
                                    } else {
                                        alert("system is error:" + data.content);
                                    }
                                }

                            });
                        }
                    }
                });
            }
            /////
        }

    }();

    $(document).ready(function() {
        quartzweb.trigger.init(2);

    });

</script>
</body>
</html>